package com.t9101DR.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.t9101DR.bean.RoomAddress;
import com.t9101DR.bean.sto;
import com.t9101DR.dao.BaseDao;
import com.t9101DR.dao.stoDao;

public class stoDaoImpl extends BaseDao implements stoDao {

	@Override
	public List<sto> list(sto sto) {
		Connection conn=null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		List<sto> list=new ArrayList<sto>();
		try {
			conn=getConnection();
			String sql="SELECT STOID,buyId,STOName,STOMaterialMan,STODiamondMan,STOSizeMan,STOTextMan,STOMaterialWoman,STODiamondWoman,STOSizeWoman,STOTextWoman,STOMaterial,STODiamond,STOSize,STOText FROM `sto` WHERE 1=1";
			if(sto!=null&&sto.getStoId()!=0) {
				sql=sql+" and STOID= "+sto.getStoId()+" ";
			}
			pstmt=conn.prepareStatement(sql);
			rs=pstmt.executeQuery();
			while(rs.next()) {
				sto bren=new sto();
				bren.setStoId(rs.getInt(1));
				bren.setBuyId(rs.getInt(2));
				bren.setStoName(rs.getString(3));
				bren.setStoMaterialMan(rs.getString(4));
				bren.setStoDiamondMan(rs.getString(5));
				bren.setStoSizeMan(rs.getInt(6));
				
				bren.setStoTextMan(rs.getString(7));
				bren.setStoMaterialWoman(rs.getString(8));
				bren.setStoDiamondWoman(rs.getString(9));
				bren.setStoSizeWoman(rs.getInt(10));
				bren.setStoTextWoman(rs.getString(11));
				bren.setStoMaterial(rs.getString(12));
				bren.setStoDiamond(rs.getString(13));
				bren.setStoSize(rs.getInt(14));
				bren.setStoText(rs.getString(15));
				
				
				list.add(bren);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			closeAll(conn, pstmt, rs);
		}
		return list;
	}

	@Override
	public int add(sto sto) {
		int count =0;
		String sql="INSERT INTO sto(buyId,STOName,STOMaterialMan,STODiamondMan,STOSizeMan,STOTextMan,STOMaterialWoman,STODiamondWoman,STOSizeWoman,STOTextWoman,STOMaterial,STODiamond,STOSize,STOText) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?) ";
		Object [] pare= {sto.getBuyId(),sto.getStoName(),sto.getStoMaterialMan(),sto.getStoDiamondMan(),sto.getStoSizeMan(),sto.getStoTextMan(),sto.getStoMaterialWoman(),sto.getStoDiamondWoman(),sto.getStoSizeWoman(),sto.getStoTextWoman(),sto.getStoMaterial(),sto.getStoDiamond(),sto.getStoSize(),sto.getStoText()};
		count=executeUpdate(sql, pare);
		return count;
	}

	@Override
	public int update(sto sto) {
		int count =0;
		String sql=" UPDATE sto set STOName=?,STOMaterialMan=?,STODiamondMan=?,STOSizeMan=?,STOTextMan=?,STOMaterialWoman=?,STODiamondWoman=?,STOSizeWoman=?,STOTextWoman=?,STOMaterial=?,STODiamond=?,STOSize=?,STOText=? WHERE STOID=?  ";
		Object [] pare= {sto.getBuyId(),sto.getStoName(),sto.getStoMaterialMan(),sto.getStoDiamondMan(),sto.getStoSizeMan(),sto.getStoTextMan(),sto.getStoMaterialWoman(),sto.getStoDiamondWoman(),sto.getStoSizeWoman(),sto.getStoTextWoman(),sto.getStoMaterial(),sto.getStoDiamond(),sto.getStoSize(),sto.getStoText()};
		count=executeUpdate(sql, pare);
		return count;
	}

	@Override
	public int deleteById(int id) {
		int count=0;
		String sql="delete from sto where STOID=?";
		Object[] params= {id};
		count=this.executeUpdate(sql, params);
		return count;
	}

}
